package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParams;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.apache.ibatis.jdbc.Null;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class SpecParamServicImpl extends ServiceImpl<SpecParamMapper, SpecParams> implements SpecParamService {
    /**
     *根据条件查询规格参数集合
     * @param cid 分类id
     * @param gid 分组id
     * @param search 是否搜索
     * @return
     */
    @Override
    public List<SpecParamDTO> selectParamsByConditions(Long cid, Long gid, Boolean search) {
        List<SpecParams> specParamsList = this.query().eq(null!=cid, "category_id", cid)
                .eq(null!=gid, "group_id", gid)
                .eq(null!=search,"searching",search)
                .list();
        return SpecParamDTO.convertEntityList(specParamsList);
    }

    /**
     * 新增规格参数
     * @param body 规格参数数据
     */
    @Override
    public void insertParam(SpecParamDTO body) {
        this.save(body.toEntity(SpecParams.class));
    }


    /**
     * 修改规格参数数据
     * @param body
     */
    @Override
    public void updateParam(SpecParamDTO body) {
        this.update(body.toEntity(SpecParams.class),new QueryWrapper<SpecParams>().eq("id",body.getId()));
    }
}
